//计算单词个数
#include "stdio.h"
#include "stdbool.h"

int main(int argc, char const *argv[])
{
  const char text1[] = "Well, here we goes.";
  const char text2[] = "And here we go... again.";
  int countWords(const char string[]);
  printf("%s - words = %i\n", text1, countWords(text1));
  printf("%s - words = %i\n", text2, countWords(text2));
  return 0;
}

int countWords(const char string[])
{
  int i, wordCount = 0;
  bool lookingForWord = true, alphabetic(const char c);
  for (i = 0; string[i] != '\0'; i++)
  {
    if (alphabetic(string[i]))
    {
      if (lookingForWord)
      {
        ++wordCount;
        lookingForWord = false;
      }
    }
    else
    {
      lookingForWord = true;
    }
  }
  return wordCount;
}

bool alphabetic(const char c)
{
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
